package o;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.util.StateSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import java.io.IOException;
import o.ah.g;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@RestrictTo({d.ˊ})
class ao extends as {
    private boolean ˋ;
    private c ˏ;

    static class c extends d {
        int[][] ˏˎ;

        c(c cVar, ao aoVar, Resources resources) {
            super(cVar, aoVar, resources);
            if (cVar != null) {
                this.ˏˎ = cVar.ˏˎ;
            } else {
                this.ˏˎ = new int[ˊ()][];
            }
        }

        void ˏ() {
            int[][] iArr = new int[this.ˏˎ.length][];
            for (int length = this.ˏˎ.length - 1; length >= 0; length--) {
                iArr[length] = this.ˏˎ[length] != null ? (int[]) this.ˏˎ[length].clone() : null;
            }
            this.ˏˎ = iArr;
        }

        int ˏ(int[] iArr, Drawable drawable) {
            int ˋ = ˋ(drawable);
            this.ˏˎ[ˋ] = iArr;
            return ˋ;
        }

        int ˋ(int[] iArr) {
            int[][] iArr2 = this.ˏˎ;
            int ˋ = ˋ();
            for (int i = 0; i < ˋ; i++) {
                if (StateSet.stateSetMatches(iArr2[i], iArr)) {
                    return i;
                }
            }
            return -1;
        }

        @NonNull
        public Drawable newDrawable() {
            return new ao(this, null);
        }

        @NonNull
        public Drawable newDrawable(Resources resources) {
            return new ao(this, resources);
        }

        public void ˋ(int i, int i2) {
            super.ˋ(i, i2);
            Object obj = new int[i2][];
            System.arraycopy(this.ˏˎ, 0, obj, 0, i);
            this.ˏˎ = obj;
        }
    }

    /* synthetic */ d ˎ() {
        return ˋ();
    }

    ao() {
        this(null, null);
    }

    public boolean isStateful() {
        return true;
    }

    protected boolean onStateChange(int[] iArr) {
        boolean onStateChange = super.onStateChange(iArr);
        int ˋ = this.ˏ.ˋ(iArr);
        if (ˋ < 0) {
            ˋ = this.ˏ.ˋ(StateSet.WILD_CARD);
        }
        return ˎ(ˋ) || onStateChange;
    }

    public void ˋ(@NonNull Context context, @NonNull Resources resources, @NonNull XmlPullParser xmlPullParser, @NonNull AttributeSet attributeSet, @Nullable Theme theme) throws XmlPullParserException, IOException {
        TypedArray ˎ = fx.ˎ(resources, theme, attributeSet, g.ˏᐧ);
        setVisible(ˎ.getBoolean(g.ˏˌ, true), true);
        ˏ(ˎ);
        ˎ(resources);
        ˎ.recycle();
        ˏ(context, resources, xmlPullParser, attributeSet, theme);
        onStateChange(getState());
    }

    private void ˏ(TypedArray typedArray) {
        c cVar = this.ˏ;
        if (VERSION.SDK_INT >= 21) {
            cVar.ʽ |= typedArray.getChangingConfigurations();
        }
        cVar.ˋॱ = typedArray.getBoolean(g.ˏـ, cVar.ˋॱ);
        cVar.ॱˊ = typedArray.getBoolean(g.ˏˍ, cVar.ॱˊ);
        cVar.ˊˋ = typedArray.getInt(g.ˑˋ, cVar.ˊˋ);
        cVar.ˊˊ = typedArray.getInt(g.ˏꓸ, cVar.ˊˊ);
        cVar.ˋˊ = typedArray.getBoolean(g.ˎﹳ, cVar.ˋˊ);
    }

    private void ˏ(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Theme theme) throws XmlPullParserException, IOException {
        c cVar = this.ˏ;
        int depth = xmlPullParser.getDepth() + 1;
        while (true) {
            int next = xmlPullParser.next();
            if (next != 1) {
                int depth2 = xmlPullParser.getDepth();
                if (depth2 < depth && next == 3) {
                    return;
                }
                if (next == 2 && depth2 <= depth && xmlPullParser.getName().equals("item")) {
                    TypedArray ˎ = fx.ˎ(resources, theme, attributeSet, g.ˏꜟ);
                    Drawable drawable = null;
                    int resourceId = ˎ.getResourceId(g.ˑˊ, -1);
                    if (resourceId > 0) {
                        drawable = ar.ˋ(context, resourceId);
                    }
                    ˎ.recycle();
                    int[] ˏ = ˏ(attributeSet);
                    if (drawable == null) {
                        do {
                            next = xmlPullParser.next();
                        } while (next == 4);
                        if (next != 2) {
                            throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
                        } else if (VERSION.SDK_INT >= 21) {
                            drawable = Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet, theme);
                        } else {
                            drawable = Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet);
                        }
                    }
                    cVar.ˏ(ˏ, drawable);
                }
            } else {
                return;
            }
        }
    }

    int[] ˏ(AttributeSet attributeSet) {
        int attributeCount = attributeSet.getAttributeCount();
        int[] iArr = new int[attributeCount];
        int i = 0;
        int i2 = 0;
        while (i < attributeCount) {
            int attributeNameResource = attributeSet.getAttributeNameResource(i);
            switch (attributeNameResource) {
                case 0:
                    attributeNameResource = i2;
                    break;
                case 16842960:
                case 16843161:
                    attributeNameResource = i2;
                    break;
                default:
                    int i3 = i2 + 1;
                    if (!attributeSet.getAttributeBooleanValue(i, false)) {
                        attributeNameResource = -attributeNameResource;
                    }
                    iArr[i2] = attributeNameResource;
                    attributeNameResource = i3;
                    break;
            }
            i++;
            i2 = attributeNameResource;
        }
        return StateSet.trimStateSet(iArr, i2);
    }

    @NonNull
    public Drawable mutate() {
        if (!this.ˋ && super.mutate() == this) {
            this.ˏ.ˏ();
            this.ˋ = true;
        }
        return this;
    }

    c ˋ() {
        return new c(this.ˏ, this, null);
    }

    @RequiresApi(21)
    public void applyTheme(@NonNull Theme theme) {
        super.applyTheme(theme);
        onStateChange(getState());
    }

    protected void ॱ(@NonNull d dVar) {
        super.ॱ(dVar);
        if (dVar instanceof c) {
            this.ˏ = (c) dVar;
        }
    }

    ao(c cVar, Resources resources) {
        ॱ(new c(cVar, this, resources));
        onStateChange(getState());
    }

    ao(@Nullable c cVar) {
        if (cVar != null) {
            ॱ(cVar);
        }
    }
}
